package com.sys.basics.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sys.basics.entity.vo.ScheduleLogsVo;
import lombok.extern.slf4j.Slf4j;
import com.sys.basics.config.jsonRes.JsonResult;
import com.sys.basics.config.jsonRes.PageParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.sys.basics.entity.SysScheduleJobLog;
import com.sys.basics.service.SysScheduleJobLogService;
import io.swagger.annotations.*;

import javax.validation.Valid;
import javax.validation.constraints.*;
import java.util.List;

/**
 * @author: ares
 * @date: 2021-10-29
 * @description: 定时任务日志表 前端控制器
 */
@Validated
@Slf4j
@Api(tags = "定时任务日志表")
@RestController
@RequestMapping("/basics/sysScheduleJobLog")
public class SysScheduleJobLogController extends AbstractController<SysScheduleJobLogService, SysScheduleJobLog> {

    @Autowired
    SysScheduleJobLogService sysScheduleJobLogService;


    @ApiOperation("清空日志")
    @DeleteMapping("/clear")
    public JsonResult clear() {
        int clearedNum = sysScheduleJobLogService.clear();
        if (clearedNum > 0) {
            return result.success("清空定时任务日志成功");
        }else {
            return result.error("清空定时任务日志失败");
        }
    }


    @ApiOperation("批量删除日志")
    @DeleteMapping("/batchRemove")
    public JsonResult batchRemove(@RequestBody List<Long> ids) {
        int removedNum = sysScheduleJobLogService.batchRemove(ids);
        if (removedNum > 0) {
            return result.success("删除定时任务日志成功");
        }else {
            return result.error("删除定时任务日志失败");
        }
    }

    @ApiOperation("分页查询")
    @PostMapping("/getPageList")
    public JsonResult<IPage<ScheduleLogsVo>> getPageList(@RequestBody PageParam<ScheduleLogsVo> param) {
        JsonResult<IPage<ScheduleLogsVo>> returnPage = new JsonResult<IPage<ScheduleLogsVo>>();
        Page<ScheduleLogsVo> page = new Page<ScheduleLogsVo>(param.getPageNum(), param.getPageSize());
        IPage<ScheduleLogsVo> pageData = sysScheduleJobLogService.getPageList(page, param.getParam());
        returnPage.success(pageData);
        return returnPage;
    }
}
